import React from 'react';
import './../../static/css/table.css';
import Row from './row';

export default class Table extends React.Component {

  constructor(props) {
	super(props);
	this.selectRow = this.selectRow.bind(this);
  }

  selectRow(row,index) {
	//console.info(row);
  }

  sorted(key) {

  }

  render() {
	return (
	  <div className={this.props.className+"_table"}>
		 <div className={this.props.className+"_title"} style={this.props.tableTitle?{}:{display:'none'}}>
			{this.props.tableTitle}
		 </div>
		 <table className={this.props.className+"_table_box"} border="0">
			<thead>
				<tr>
					{
						this.props.columns? 
							this.props.columns.map(res=>(
									<th key={res.name} width={res.width?res.width:'100'} align={res.align?res.align:'left'} onClick={this.sorted(res.sorted)}>{res.title}</th>
								)
							):
						''
					}
				</tr>
			</thead>
			<tbody>
				{
					this.props.dataSource?this.props.dataSource.map((object,index)=>(
						<Row key={index} columns={this.props.columns} obj={object} className={this.props.className} index={index} onClick={this.selectRow}/>                    
					)):<tr height='200'><td colspan={this.props.columns.length} align="center" style={{color:'red'}}>您当前发布没有任何主题帖</td></tr>
				}
			</tbody>
		 </table>
	  </div>
	);
  }
}